package fons.model.ontology;

import java.util.Collections;
import java.util.List;
import java.util.Set;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import fons.model.ontology.language.Named;

public class Role extends AbstractContextDependent implements Named {
	private final String name;
	private final List<String> synonymes = Lists.newArrayList();
	
	private boolean hasValue = false;
	private Set<Dimension> implicitDimensions = Sets.newHashSet();
	private Set<Dimension> definedDimensions = Sets.newHashSet();
	
	Role(String name, Context context) {
		super(context);
		this.name = name;
		synonymes.add(name);
	}
	
	public void setHasValue (boolean hasValue) {
		this.hasValue = hasValue;
	}
	
	public boolean hasValue () {
		return this.hasValue;
	}
	
	public void addSynonyme(String synonyme) {
		this.synonymes.add(synonyme);
	}
	
	public List<String> getSynonymes () {
		return Collections.unmodifiableList(synonymes);
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Role other = (Role) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Role [name=" + name + "]";
	}

	public Set<Dimension> getImplicitDimensions() {
		return Collections.unmodifiableSet(implicitDimensions);
	}

	public void addImplicitDimensions(Set<Dimension> implicitDimensions) {
		this.implicitDimensions.addAll(implicitDimensions);
	}

	public boolean isImplicit() {
		return implicitDimensions.size() > 0;
	}
	
	public void addDefinedDimensions (Set<Dimension> dimensions) {
		this.definedDimensions.addAll(dimensions);
	}
	
	public Set<Dimension> getDefinedDimensions() {
		return Collections.unmodifiableSet(this.definedDimensions);
	}
}
